package com.yaowk.system.server.service.impl;

import com.yaowk.system.api.model.Login;
import com.yaowk.system.server.dao.UserDao;
import com.yaowk.system.server.entity.SysLogin;
import com.yaowk.system.server.entity.SysUser;
import com.yaowk.system.server.service.base.LoginServiceBase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

@Service
public class LoginServiceImpl extends LoginServiceBase {

    @Autowired
    private UserDao userDao;

    @Override
    @Transactional
    public void login(Login login) {
        super.add(login);

    }

    @Override
    public SysLogin model2Entity(Login model) {
        SysLogin sysLogin = super.model2Entity(model);
        if (isNotEmpty(sysLogin)) {
            if (isNotEmpty(sysLogin.getUserId())) {
                SysUser sysUser = userDao.findOne(sysLogin.getUserId());
                sysLogin.setUser(sysUser);
            }
        }
        return sysLogin;
    }
}